
package com.cari.baju.yog.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cari.baju.yog.R;
import com.cari.baju.yog.entity.E_Toko;

public class AdapterCari extends BaseAdapter {

    private LayoutInflater inflater;
    private List<E_Toko> listToko;

    public AdapterCari(Context context, List<E_Toko> listToko) {
        this.listToko = listToko;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listToko.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return listToko.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    static class Holder {
        TextView txtTitle, txtDistance;
    }

    @Override
    public View getView(int pos, View view, ViewGroup parent) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = inflater.inflate(R.layout.item_list_pencarian, null);
            holder.txtTitle = (TextView) view.findViewById(R.id.title_toko);
            holder.txtDistance = (TextView) view.findViewById(R.id.distance_toko);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.txtTitle.setText(listToko.get(pos).getName());
        holder.txtDistance.setText(String.format("%.2f", listToko.get(pos).getJarak()) + " km");
        return view;
    }

}
